package com.example.wangyuyuan.custemaddandsubview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;


/**
 * 自定义加减按钮测试
 */

public class MainActivity extends AppCompatActivity {

    private CustomAddAndSubView customAddAndSubView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        customAddAndSubView = (CustomAddAndSubView) findViewById(R.id.customAddAndSubView);
//        customAddAndSubView.setMiddleDistance(100);
//        customAddAndSubView.setButtonBgColor(R.color.colorAccent,R.color.colorPrimary);
        customAddAndSubView.setOnNumChangeListener(new CustomAddAndSubView.OnNumChangeListener() {
            @Override
            public void onNumChange(View view, int stype, int num) {
                switch (stype) {
                    case 1:
                        Toast.makeText(MainActivity.this, "添加成功", Toast.LENGTH_LONG).show();
                        break;
                    case 0:
                        if (num <= 0) {
                            customAddAndSubView.setNum(0);
                        } else {
                            Toast.makeText(MainActivity.this, "删除成功", Toast.LENGTH_LONG).show();
                        }
                        break;
                    default:
                        Toast.makeText(MainActivity.this, "操作失败", Toast.LENGTH_LONG).show();
                        break;
                }

            }
        });
    }
}
